
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
function operatesearch() {
    if($("#customerId").val()!=""){
        if($("#customerId").val().length<10){
            $("#kk").css({
                display: "inline"
            });
            return false;
        }else {
            $("#kk").css({
                display: "none"
            });
        }
    }else {
        $("#kk").css({
            display: "none"
        });
    }

    $.ajax({
        url: root.sroreinter.houseList,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "houseId":$("#houseId").val(),
            "houseName":$("#houseName").val(),
            "customerName":$("#customer_Name").val(),
            "customerId":$("#customerId").val(),
            "pageNum":"1",
            "pageSize":"20"
        }),
        success: function (data) {
            var pk=""
            if(data.data!=null){
                pk=data.data.pageCount
                couponlist1(data.data.data);
            }else {
                couponlist1(0);
                pk=0
            }
            $('.M-box3').pagination({
                pageCount:pk,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    console.log(api)
                    $.ajax({
                        url: root.sroreinter.houseList,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":20,
                            "houseId":$("#houseId").val(),
                            "houseName":$("#houseName").val(),
                            "customerName":$("#customer_Name").val(),
                            "customerId":$("#customerId").val(),

                        }),
                        success: function (result) {
                            couponlist1(result.data.data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

// var j = 0;
function couponlist1(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    $.each(data, function (i, field) {
        var rowData = new Array();
        rowData.push(field.house_id);
        rowData.push(field.coustomerId);
        rowData.push(field.house_name);
        rowData.push(field.loginAccount);
        rowData.push(field.coustomerName);
        rowData.push(field.group_name);
        rowData.push(field.productNum);
        rowData.push(field.create_at);
        rowData.push(field.create_by_name);
        rowData.push(field.status);
        rowData.push(field.designated_warehouse);
        rowData.push(field.call_men);//低下限提醒人
        dataSource.push(rowData);

    });

    initData(dataSource);

    function initData(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": false,
            "destroy": false,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu":[10,20,30],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val=""
                        var names=row[1]
                        $.each(names,function(k,v){
                            val+='<div>'+v+'</div>'

                        })
                        return val;

                    },
                    "targets": 1
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val=""
                        var names=row[3]
                        $.each(names,function(k,v){
                            val+='<div>'+v+'</div>'

                        })
                        return val;

                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val=""
                        var ids=row[4]
                        for(var i=0;i<ids.length;i++){
                            val+='<div>'+ids[i]+'</div>'
                        }

                        return val;
                    },
                    "targets": 4
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[5]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 5
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[6]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 6
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[7];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets": 7
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[8]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 8
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[11]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 9
                },
                {
                    "render": function (data, type, row, meta) {
                        if(row[9]==10){
                            var val='<div class="switch"> <div style="width: 63px;height: 27px;margin-top: 31px;margin-left: 19px;" class="btn_fath clearfix on" onclick="toogle(this,'+row[0]+','+row[10]+')"> <div class="move" data-state="on"></div> <div style="margin-top: 0px;margin-left: -2px;" class="btnSwitch btn1">开</div> <div class="btnSwitch btn2 ">关</div> </div> </div>'

                            return val;

                        }else {
                            var val='<div class="switch"><div style="width: 63px;height: 27px;margin-top: 15px;margin-left: 19px;" class="btn_fath clearfix off" onclick="toogle(this,'+row[0]+','+row[10]+')"><div class="move" data-state="off"></div><div class="btnSwitch btn1">开</div> <div class="btnSwitch btn2 ">关</div> </div> </div>'

                            return val;
                        }
                    },
                    "targets":10
                },

                {
                    "render": function (data, type, row, meta) {
                        if(row[10]==0||row[9]==20){
                            var val ='<a onclick="edityuncang(\''+row[0]+'\')">云仓编辑</a><br> <a onclick="orderInfo(\'商品设置\',\'setupgoods.html\',\''+row[0]+'\')">商品设置</a><br><a style="opacity: 0.2">查看前台链接</a>'
                            return val;
                        }else {
                            var val ='<a onclick="edityuncang(\''+row[0]+'\')">云仓编辑</a><br> <a onclick="orderInfo(\'商品设置\',\'setupgoods.html\',\''+row[0]+'\')">商品设置</a><br><a onclick="copys(\''+row[0]+'\',\''+row[10]+'\')">查看前台链接</a>'
                            return val;
                        }


                    },
                    "targets": 11
                },
            ]
        });

    };
}

/*跳转详情*/
function orderInfo(title,url,data){
    sessionStorage.setItem("houstId",data);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

//滑动按钮效果
function toogle(th,ids,shangpin){
    var ele = $(th).children(".move");
    if(ele.attr("data-state") == "on"){

            var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >关闭后此云仓将无法查看下单</span>', {title:'提示',btn: ['确定', '取消']}, function(index){

                $.ajax({
                    url: 'https://'+ window.location.host +'/api/admin/anobodyhouse/updateHouseMsg',
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    contentType: "application/json",
                    data: JSON.stringify({
                        "houseName":"",
                        "houseAddress":"",
                        "groupId":"",
                        "groupName":"",
                        "memberIdInfo":[],
                        "customerInfo":[],
                        "pictureUrl":"",
                        "status":"20",
                        /* "createById":JSON.parse(localStorage.getItem("loginData")).user.user_ID,
                         "createByName":JSON.parse(localStorage.getItem("loginData")).user.username*/
                        "createById":1,
                        "createByName":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "houseId":ids
                    }),
                    success: function (data) {
                       if(data.errorCode==0){
                           ele.animate({left: "0"}, 300, function(){
                           ele.attr("data-state", "off");
                           $(th).removeClass("on").addClass("off");
                           });
                           operatesearch()
                       }else {
                           $.Huimodalalert(data.msg, 2000);
                           operatesearch()
                       }

                    }
                });
                layer.close(curInd);
            },function(){
                layer.close(curInd);

            });




    }else if(ele.attr("data-state") == "off"){


                $.ajax({
                    url: 'https://'+ window.location.host +'/api/admin/anobodyhouse/updateHouseMsg',
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    contentType: "application/json",
                    data: JSON.stringify({
                        "houseName":"",
                        "houseAddress":"",
                        "groupId":"",
                        "groupName":"",
                        "memberIdInfo":[],
                        "customerInfo":[],
                        "pictureUrl":"",
                        "status":"10",
                        /* "createById":JSON.parse(localStorage.getItem("loginData")).user.user_ID,
                         "createByName":JSON.parse(localStorage.getItem("loginData")).user.username*/
                        "createById":1,
                        "createByName":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "houseId":ids
                    }),
                    success: function (data) {
                        if(data.errorCode==0){
                            $.Huimodalalert(' 开启成功', 2000);
                            ele.animate({left: '60px'}, 300, function(){
                            $(this).attr("data-state", "on");
                            $(th).removeClass("off").addClass("on");
                            });
                            operatesearch()
                        }if(data.errorCode==5){
                            $.Huimodalalert(' 云仓商品数据为空，无法开启', 2000);
                        } else if(data.errorCode==1){
                            $.Huimodalalert(data.msg, 2000);
                        }


                    }
                });
            }




}

//新增云仓
function addyuncang() {
    $("#yuncang").modal("show");
    $(".addressTitle").html("新增方盛云仓");
    $("#df").html("上传")
}
//取消新增云仓
function close_model() {
    console.log($(".addressTitle").html())
    $("#yuncang").modal("hide");
    $(".qing").val("");
    $("#tableid").find("table>tbody").html("");
    $("#tableid2").find("table>tbody").html("");
    $(".qing2").attr("src","");
    $("#call_men").val("")
    $("#call_phone").val("")

}


var kehu=""


//指定客户联想
function zhiding(){
    var customername=$("#customername").val();
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/amembership/customer/getCustomers',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "customerIdOrCustomerName":customername,
            "pageSize":500,
            "pageNo":1
        }),
        success: function (data) {
            console.log(data)
            if(data.errorCode=="0"){
                var jsonObj =data.data.data;
                $("#tuan").html("");
                if(jsonObj==""){
                    $("#tuan").html("<li>无数据</li> ");
                }else {
                    console.log(jsonObj)
                    kehu=jsonObj
                    var optionstring = "";
                    for (var  i= 0; i < jsonObj.length; i++) {

                        optionstring += "<li style='width: 335px;' class='dda' onclick='relatssion(\""+ jsonObj[i].customerId+"\",\""+jsonObj[i].customerName+"\")' data-align=\"" + jsonObj[i].customerId + "\" > " + jsonObj[i].customerName + "</li>";
                    }
                    $("#tuan").html(optionstring);
                    sf()
                    $(".zhidings").animate({scrollTop:"0"},1);
                    index=-1
                    $("#tuan").show()
                }

            }else{
                $("#tuan").html("<li>无数据</li> ");
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//授权收货人取光标
/*$("#customername").focus(function () {
    $("#tuan").show()
});*/
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#customername").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan").hide()
    }
})
function relatssion(id,ce) {
    $("#customername").val(ce).text(id)
    $("#tuan").hide()
}
function sf() {
    //指定客户上下键
    var list = document.getElementById("tuan").getElementsByTagName("li");
    var index = -1;
    function addIndex() {
        index = index>=list.length ? 0 : ++index;
        return index;
    }
    function reduceIndex() {
        index = index <= 0 ? -1 : --index;
        return index;
    }
    document.onkeydown = function(e) {
        e = e || window.event;
        switch(e.keyCode){
            case 13://回车
                var t = document.getElementById("tuan").getElementsByTagName("li")[index].innerHTML;
                var t2=document.getElementById("tuan").getElementsByTagName("li")[index].dataset.align
                $("#customername").val(t).text(t2)
                $("#tuan").hide()
                break;
            case 38://上键
                reduceIndex();
                setLiColorByClass(38);
                break;
            case 40://下键
                addIndex();
                setLiColorByClass(40);
                break;
        }
        function setLiColorByClass(keyCode){
            for(var i = 0,len=list.length; i<len; i++) {
                list[i].className = i==index ? "current" : "";
                i==index ? console.log($(list[i]).offset().top-$(".zhidings").offset().top) : "";
                if(i==index){
                    var offsetParent = $(list[i]).offset().top-$(".zhidings").offset().top;
                    if(keyCode==40){
                        if(offsetParent>121){
                            $(".zhidings").animate({scrollTop:"+=24"},1);
                        }
                    }else if(keyCode==38){
                        if(offsetParent<1){
                            $(".zhidings").animate({scrollTop:"-=24"},1);
                        }
                    }

                }
            }

        }
    };

}

//权限联想
function quanxianlian(){
    var quanxian=$("#quanxian").val();
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/amembership/member/getMembers',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "loginAccount":quanxian,
            "status":"10",
            "pageSize":500,
            "pageNo":1
        }),
        success: function (data) {
            console.log(data)
            if(data.errorCode=="0"){
                var jsonObj =data.data.data;
                $("#tuan2").html("");
                if(jsonObj==""){
                    $("#tuan2").html("<li>无数据</li> ");
                }else {
                    console.log(jsonObj)

                    var optionstring = "";
                    for (var  i= 0; i < jsonObj.length; i++) {
                        optionstring += "<li class='dda' onclick='quanrelatssion(\""+ jsonObj[i].memberId+"\",\""+jsonObj[i].loginAccount+"\")' data-align=\"" + jsonObj[i].memberId + "\" > " + jsonObj[i].loginAccount + "</li>";
                    }

                    $("#tuan2").html(optionstring);
                    fs()
                    $(".quanxians").animate({scrollTop:"0"},1);
                    index2=-1
                    $("#tuan2").show()
                }
            }else{
                $("#tuan2").html("<li>无数据</li>");
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//授权收货人取光标
/*$("#quanxian").focus(function () {
    $("#tuan2").show()
});*/
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan2").length == 0 && $(e.target).closest("#quanxian").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan2").hide()
    }
})
function quanrelatssion(id,ce) {
    $("#quanxian").val(ce).text(id)
    $("#tuan2").hide()
}
//上下键
function fs() {
    var list2 = document.getElementById("tuan2").getElementsByTagName("li");
    var index2 = -1;
    function addIndex2() {
        index2 = index2>=list2.length ? 0 : ++index2;
        return index2;
    }
    function reduceIndex2() {
        index2 = index2 <= 0 ? -1 : --index2;
        return index2;
    }
    document.onkeydown = function(e2) {
        e2 = e2 || window.event;
        switch(e2.keyCode){
            case 13://回车
                var t2 = document.getElementById("tuan2").getElementsByTagName("li")[index2].innerHTML;
                var t22=document.getElementById("tuan2").getElementsByTagName("li")[index2].dataset.align
                $("#quanxian").val(t2).text(t22)
                $("#tuan2").hide()
                break;
            case 38://上键
                reduceIndex2();
                setLiColorByClass2(38);
                break;
            case 40://下键
                addIndex2();
                setLiColorByClass2(40);
                break;
        }
        function setLiColorByClass2(keyCode){
            for(var i2 = 0,len2=list2.length; i2<len2; i2++) {
                list2[i2].className = i2==index2 ? "current" : "";
                i2==index2 ? console.log($(list2[i2]).offset().top-$(".quanxians").offset().top) : "";
                if(i2==index2){
                    var offsetParent2 = $(list2[i2]).offset().top-$(".quanxians").offset().top;
                    if(keyCode==40){
                        if(offsetParent2>121){
                            $(".quanxians").animate({scrollTop:"+=24"},1);
                        }
                    }else if(keyCode==38){
                        if(offsetParent2<1){
                            $(".quanxians").animate({scrollTop:"-=24"},1);
                        }
                    }

                }
            }

        }
    };
}

















//指定客户添加
function addcustomer() {
    var customername = $("#customername").val();
    var customerID = $("#customername").text();
    if(customername.replace(/^ +| +$/g,'')==''){
        $.Huimodalalert('指定客户不能为空', 2000);
        return false
    }
    console.log(customerID)
    if(customerID==""){
        $.Huimodalalert('暂无此客户信息，请重新输入', 2000);
        return false;
    }
    console.log(customerID)
    var isTr = checkName(customername,customerID);
    if (isTr == true && customername != null && customername != ''){
        var handStr = '';
        handStr += '<tr style="margin-left: 30px">';
        handStr += '<td style=" text-align: left;padding-left:86px;width: 326px;"><span class="customername" style="display:inline-block;margin-left:-92px;font-size: 1px;"><i>' + customerID + '</i></span><span class="customername2" style="display:inline-block;margin-left:21px;font-size: 1px;"><i>' + customername + '</i></span></td>';
        handStr += '<td style="padding-left: 0px;width: 30px"  onclick="Deletelinkman(this)"><a  href="javascript:;">删除</a></td>';
        handStr += '<td style="padding-left: 22px;"><span></span></td>';
        handStr += '</tr>';
        $("#tableid").find("table>tbody").prepend(handStr);
        $("#customername").val('');
        $("#customername").text("")
    }
}
//权限账号添加
function addquanxian() {
    var quanxian = $("#quanxian").val();
    var quanxianid = $("#quanxian").text();
    if(quanxian.replace(/^ +| +$/g,'')==''){
        $.Huimodalalert('权限账号不能为空', 2000);
        return false
    }
    if(quanxianid==""){
        $.Huimodalalert('<span style="font-size: 16px;">账号不存在/账号未开启，添加失败</span>', 2000);
        return false;
    }
    var isTr = checkName2(quanxian);
    if (isTr == true && quanxian != null && quanxian != ''){
        var handStr = '';
        handStr += '<tr style="margin-left: 30px">';
        handStr += '<td style=" text-align: left;padding-left:10px;width: 250px;"><span class="quanxianname" style="display:inline-block;margin-left:45px;font-size: 1px;"><i>' + quanxian + '</i></span><span class="quanxianname2" style="display:none;margin-left:45px;font-size: 1px;"><i>' + quanxianid + '</i></span></td>';
        handStr += '<td style="padding-left: 0px;width: 30px"  onclick="Deletelinkman(this)"><a  href="javascript:;">删除</a></td>';
        handStr += '<td style="padding-left: 22px;"><span></span></td>';
        handStr += '</tr>';
        $("#tableid2").find("table>tbody").prepend(handStr);
        $("#quanxian").val('');
    }

}
//校验添加的指定客户
function checkName(name,ids) {
    var flag = true;
    var arr = [];

    $('#tableid tbody tr').each(function (i, dom){
        arr.push({
            "ID": $(dom).find('.customername').text(),
            "name": $(dom).find('.customername2').text(),
        });
        console.log(arr);
        //手机号码和姓名不能重复
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].ID == ids) {
                $.Huimodalalert('该指定客户已存在', 2000);
                flag = false;
            }


        }
        if (arr.length >= 10) {
            $.Huimodalalert('最多可添加10个指定客户', 2000);
            flag = false;
        }

    });
    return flag;
}
//校验添加的权限账号
function checkName2(name) {
    var flag = true;
    var arr2=[];
    $('#tableid2 tbody tr').each(function (i, dom){
        arr2.push({
            "name": $(dom).find('.quanxianname').text(),
        });
        for (var i = 0; i < arr2.length; i++) {
            if (arr2[i].name == name) {
                $.Huimodalalert('该权限账号已存在', 2000);
                flag = false;
            }
        }
        if (arr2.length >= 20) {
            $.Huimodalalert('最多可添加20个权限账号', 2000);
            flag = false;
        }

    });
    return flag;
}



//删除指定客户
function Deletelinkman(k) {
    $(k).parent().remove();
}


//客户归属
function myFunction(){
    var user_data = {
        "pageNum":1,

        "pageSize":500,

    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            var jsonObj =data.group;
            $("#tuank").html("");
            if(jsonObj==""){
                $("#tuank").html("<li>无数据</li> ");
            }else {
                console.log(jsonObj)

                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li class='dda' onclick='relation("+ jsonObj[i].id+",\""+jsonObj[i].organization_name+"\")' data-align=\"" + jsonObj[i].id + "\" > " + jsonObj[i].organization_name + "</li>";
                }
                $("#tuank").html(optionstring);
                kehuguishu()
                $(".kehus").animate({scrollTop:"0"},1);
                index3=-1
                $("#tuank").show()

            }
        }else{
            $("#tuank").html("<li>无数据</li> ");
        }
    }
    /*root.member.getGroup*/
    web.doAjax(root.member.getGroup,'post',user_data, succCallBack);

}
/*//取光标
$("#organization_name").focus(function () {
    $("#tuank").show()
});*/
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuank").length == 0 && $(e.target).closest("#organization_name").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuank").hide()
    }
})
function relation(id,ce) {
    $("#organization_name").val(ce).text(id)
    $("#tuank").hide()
    console.log($("#organization_name").text())
}



function kehuguishu() {
    var list2 = document.getElementById("tuank").getElementsByTagName("li");
    var index2 = -1;
    function addIndex2() {
        index2 = index2>=list2.length ? 0 : ++index2;
        return index2;
    }
    function reduceIndex2() {
        index2 = index2 <= 0 ? -1 : --index2;
        return index2;
    }
    document.onkeydown = function(e2) {
        e2 = e2 || window.event;
        switch(e2.keyCode){
            case 13://回车
                var t2 = document.getElementById("tuank").getElementsByTagName("li")[index2].innerHTML;
                var t22=document.getElementById("tuank").getElementsByTagName("li")[index2].dataset.align
                $("#organization_name").val(t2).text(t22)
                $("#tuank").hide()
                break;
            case 38://上键
                reduceIndex2();
                setLiColorByClass2(38);
                break;
            case 40://下键
                addIndex2();
                setLiColorByClass2(40);
                break;
        }
        function setLiColorByClass2(keyCode){
            for(var i2 = 0,len2=list2.length; i2<len2; i2++) {
                list2[i2].className = i2==index2 ? "current" : "";
                i2==index2 ? console.log($(list2[i2]).offset().top-$(".kehus").offset().top) : "";
                if(i2==index2){
                    var offsetParent2 = $(list2[i2]).offset().top-$(".kehus").offset().top;
                    if(keyCode==40){
                        if(offsetParent2>121){
                            $(".kehus").animate({scrollTop:"+=24"},1);
                        }
                    }else if(keyCode==38){
                        if(offsetParent2<1){
                            $(".kehus").animate({scrollTop:"-=24"},1);
                        }
                    }

                }
            }

        }
    };
}
//formdata上传图片公用方法
//触发事件
var ipcuu=""
var pathss=""
function addBtn(cen,ir) {
    ipcuu=ir
    $(cen).prev().trigger('click');
}
var formData = new FormData();
// 提交上传图片
function getupfilerul(can,e){
    var formData = new FormData();
    formData.append('file',$(can)[0].files[0]);
    $.ajax({
        url: root.inter.imgUpload,
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData : false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType : false,
        data: formData,
        success: function (data) {
            pathss=data[0].fullPath
            for(var i=0; i<data.length; i++){
                $(can).prev().val(data[0].reletivePath)
                $(can).prev().text(data[0].reletivePath)
            }
        }
    })
}
// 上传图片返现
function putDataToPage(e,can) {
    verificationPicFileType(can)
    verificationPicFileSize(can)
    verificationPicFileMeasure(can)
    for(var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if(!(/^image\/.*$/i.test(file.type))) {
            continue; //不是图片 就跳出这一次循环
        }


        //实例化FileReader API
        var freader = new FileReader();
        freader.readAsDataURL(file);
        console.log(e.path)
        console.log(can)
        freader.onload = function (e) {
            console.log(can)
            $(can).parent().prev().children().attr("src", e.target.result);
            console.log(e)
            $(can).next().text('重新上传')
            getupfilerul(can,e)
        }
    }
    formData.append('file', $(can)[0].files[0]);
}
// 图片类型验证
function verificationPicFileType(file) {
    var flag=false;
    var fileTypes = [".jpg", ".png",".JPG", ".PNG"];
    var filePath = file.value;
    //当括号里面的值为0、空字符、false 、null 、undefined的时候就相当于false
    if(filePath){
        var isNext = false;
        var fileEnd = filePath.substring(filePath.indexOf("."));
        for (var i = 0; i < fileTypes.length; i++) {
            if (fileTypes[i] == fileEnd) {
                isNext = true;
                flag= true;
                break;
            }
        }
        if (!isNext){
            $.Huimodalalert('不接受此类型，请上传jpg或png格式',2000);
            file.value = "";
            flag=false;
        }
    }
    return flag;
}
//图片大小验证
function verificationPicFileSize(file) {
    var flag=false;
    var fileSize = 0;
    var fileMaxSize = Number(200);
    var filePath = file.value;
    if(filePath){
        fileSize =file.files[0].size;
        var size = fileSize / Number(1024);
        if (size > fileMaxSize) {
            $.Huimodalalert('图片大小不可超过200KB',2000);
            file.value = "";
            flag=false;
        }else{
            flag=true;
        }
    }
    return flag;
}
var op=2

//图片尺寸验证
function verificationPicFileMeasure(file) {
    var flag=false;
    var filePath = file.value;
    if(filePath){
        //读取图片数据
        var filePic = file.files[0];
        var reader = new FileReader();
        reader.onload = function (e) {
            var data = e.target.result;
            //加载图片获取图片真实宽度和高度
            var img = new Image();
            img.src= data;
            img.onload = function(){
                var width = img.width;
                var height = img.height;
                if (width != 150 | height != 150){
                    $.Huimodalalert('图片尺寸为150*150px',2000);
                    $("#yuncangsrc").attr("src","")
                    $("#df").html("上传")
                    op=1
                    file.value = "";
                    flag=false;
                }else {
                    op=2
                    flag=true;
                }

            };

        };
        reader.readAsDataURL(filePic);
    }else{
        flag=false;
    }
    return flag;
}

var houseIds=""

// 编辑方盛云仓
function edityuncang(hostids) {
    houseIds=hostids
    $("#yuncang").modal("show");
    $(".addressTitle").html("编辑方盛云仓");
    //渲染
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/anobodyhouse/searchHouseMsg',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: {
            "houseId":hostids,

        },
        success: function (data) {
           console.log()
            $("#yuncangnames").val(data.data.houseName)//云仓名称
            $("#yuncangAddress").val(data.data.houseAddress)//云仓地址
            $("#organization_name").val(data.data.groupName)//客户归属
            $("#organization_name").text(data.data.groupId)//客户归属
            $("#yuncangsrc").attr("src",data.data.pictureUrl)
            $("#call_men").val(data.data.callMen)
            $("#call_phone").val(data.data.callPhone)
            var handStr2 = '';
            $.each(data.data.customerInfo,function(k,v){
                handStr2 += '<tr style="margin-left: 30px">';
                handStr2 += '<td style=" text-align: left;padding-left:86px;width: 326px;"><span class="customername" style="display:inline-block;margin-left:-92px;"><i>' + v.customerId  + '</i></span><span class="customername2" style="display:inline-block;margin-left:21px;"><i>' + v.customerName+ '</i></span></td>';
                handStr2 += '<td style="padding-left: 9px;width: 30px"  onclick="Deletelinkman(this)"><a  href="javascript:;">删除</a></td>';
                handStr2 += '<td style="padding-left: 22px;"><span></span></td>';
                handStr2 += '</tr>';
            })
            $("#tableid").find("table>tbody").prepend(handStr2);


            var handStr = '';
            $.each(data.data.memberIdInfo,function(k,v){
            handStr += '<tr style="margin-left: 30px">';
            handStr += '<td style=" text-align: left;padding-left:10px;width: 250px;"><span class="quanxianname" style="display:inline-block;margin-left:45px;"><i>' + v.loginAccount + '</i></span><span class="quanxianname2" style="display:none;margin-left:45px;"><i>' + v.memberId + '</i></span></td>';
            handStr += '<td style="padding-left: 9px;width: 30px"  onclick="Deletelinkman(this)"><a  href="javascript:;">删除</a></td>';
            handStr += '<td style="padding-left: 22px;"><span></span></td>';
            handStr += '</tr>';

            })
            $("#tableid2").find("table>tbody").prepend(handStr);
            },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });


}


//保存
function queding() {
    //获取指定客户
    var customernames = [];
    $('#tableid tbody tr').each(function (i, dom){
        customernames.push({
            "customerId":$(dom).find('.customername').find('i').text(),
            "customerName": $(dom).find('.customername2').find('i').text(),
        });

    });

    console.log(customernames)
    //获取权限账号
    var quanxiannames = [];
    $('#tableid2 tbody tr').each(function (i, dom){
        quanxiannames.push({
            "memberId":$(dom).find('.quanxianname2').find('i').text(),
            "loginAccount": $(dom).find('.quanxianname').find('i').text(),
        });

    });

    var tupian=""
    if(pathss==""){
        tupian= $("#yuncangsrc").attr("src")
    }else {
        tupian=pathss
    }
var  starta=""
    var idf=""
    if($(".addressTitle").html()=="编辑方盛云仓"){
        starta=""
        idf=houseIds
    }else {
        starta=""
        idf=""
    }
    if($("#yuncangnames").val()==""){
        $.Huimodalalert('请填写云仓名称！',2000);
        return false;
    }
    if($("#yuncangAddress").val()==""){
        $.Huimodalalert('请填写云仓地址！',2000);
        return false;
    }
   /* if(customernames==""){
        $.Huimodalalert('请填写指定客户！',2000);
        return false;
    }*/
    if(quanxiannames==""){
        $.Huimodalalert('请填写权限账号！',2000);
        return false;
    }
    if($("#organization_name").val()==""){
        $.Huimodalalert('请填写客户归属！',2000);
        return false;
    }
    var tupians=""
    if(op==1){
        tupians=""
    }else {
        tupians= tupian
    }
    if($("#call_phone").val()!=""){
        if($("#call_phone").val().length != Number(11)){
            $.Huimodalalert('请填写正确的手机号码',2000);
            return false;
        }
    }

    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/anobodyhouse/updateHouseMsg',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "houseName":$("#yuncangnames").val(),
            "houseAddress":$("#yuncangAddress").val(),
            "groupId":$("#organization_name").text(),
            "groupName":$("#organization_name").val(),
            "memberIdInfo":quanxiannames,
            "customerInfo":customernames,
            "pictureUrl":tupians,
            "status":starta,
            "createById":JSON.parse(web.readCookie("loginData")).user.user_ID,
            "createByName":JSON.parse(web.readCookie("loginData")).user.name,
            "houseId":idf,
            "callMen":$("#call_men").val(),
            "callPhone":$("#call_phone").val(),
        }),
        success: function (data) {
            if(data.errorCode==0){
                if($(".addressTitle").html()=="编辑方盛云仓"){
                    $.Huimodalalert('编辑成功！',2000);
                    $("#yuncang").modal("hide");
                    $("#yuncang").modal("hide");
                    $(".qing").val("");
                    $("#tableid").find("table>tbody").html("");
                    $("#tableid2").find("table>tbody").html("");
                    $(".qing2").attr("src","");
                    $("#call_men").val("")
                    $("#call_phone").val("")
                    operatesearch()
                }else {
                    $.Huimodalalert('新增成功！',2000);
                    $("#yuncang").modal("hide");
                    $("#yuncang").modal("hide");
                    $(".qing").val("");
                    $("#tableid").find("table>tbody").html("");
                    $("#tableid2").find("table>tbody").html("");
                    $(".qing2").attr("src","");
                    $("#call_men").val("")
                    $("#call_phone").val("")
                    operatesearch()
                }

            }else {
                $.Huimodalalert(data.msg,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });

}
//查看云仓链接
function copys(hostid,wostid) {
$("#newPath").val('https://'+ window.location.host +'/h5/unmannedStorehouse/screen/index.html?houseId='+hostid+'&desWarehouse='+wostid+'')
    $("#download").modal("show");

}
//复制链接
function copyNewUrl() {
    var Url=document.getElementById("newPath");
    Url.select(); // 选择对象
    console.log($("#newPath").val())
    var pashs=$("#newPath").val()
    pashs = pashs.match(/desWarehouse=(\S*)/)[1];//截取链接desWarehouse=后的数据
    if(pashs==0){
        $.Huimodalalert('商品未设置！', 2000);
        return false;
    }else {
        document.execCommand("Copy"); // 执行浏览器复制命令
        layer.msg('复制成功！', {icon: 6,time:1000});
        $("#download").modal("hide");
    }

}
